package com.glxy.service.impl;

import com.glxy.dao.impl.ProviderDaoImpl;
import com.glxy.dao.impl.UserDaoImpl;
import com.glxy.pojo.Provider;
import com.glxy.service.ProviderService;

import java.util.ArrayList;

public class ProviderServicelmpl implements ProviderService {
    public  ArrayList<Provider> findProvider(String proName){

        return new ProviderDaoImpl().findByName(proName);

    }
    public Integer totalCount() {
        return new ProviderDaoImpl().findAll().size();
    }


    public ArrayList<Provider> findAllProviderPages(Integer pageSize, Integer pageNo) {
        ArrayList<Provider> page = new ArrayList<>();
        ArrayList<Provider> list = new ProviderDaoImpl().findAll();
        for (int i = pageSize*(pageNo - 1); i < pageSize*(pageNo - 1) + pageSize; i++) {
            if (i < list.size()) page.add(list.get(i));
        }
        return page;
    }

    @Override
    public ArrayList<Provider> getProviderList() {
        ProviderDaoImpl providerDao = new ProviderDaoImpl();
        return providerDao.findAll();
    }


    public void insertProvider(Provider provider) {
        ProviderDaoImpl providerDao = new ProviderDaoImpl();
        providerDao.insert(provider);
    }

    public void update (Provider provider){
        ProviderDaoImpl providerDao = new ProviderDaoImpl();
        providerDao.update(provider);
    }

    public void delete(Long id) {
        ProviderDaoImpl providerDao = new ProviderDaoImpl();
        providerDao.delete(id);
    }
}
